
ifndef verNum
	# 版本号以2024年1月1号为基准，过去多少个小时，就是多少版本号，即同一个小时内编译，版本号是一样的。
	verNum := $$(( $(shell date -d "-54 year" +%s) / 3600 ))
endif

buildTime := $(shell date +%Y%m%d-%H%M)
export CGO_ENABLED := 1

build:
	# go env -w CGO_ENABLED=0
	# go build  -ldflags "-w -linkmode external -extldflags -static" -o ./bin/wick ./cmd/wick
	go build  -ldflags "-w -extldflags -static" -o ./bin/wick ./cmd/wick

cluster:
	# x86编译选项特殊，保证可以在任意Linux上都能跑，但不支持交叉编译 CGO_ENABLED=1
	# go build  -ldflags "-w -linkmode external -extldflags -static" ./cmd/cluster
	@echo version=${verNum} buildTime=${buildTime}
	go build -ldflags="-w -s -X main.major=1 -X main.minor=1 -X main.version=${verNum} -X main.buildTime=${buildTime} -linkmode external -extldflags -static" -buildmode=pie -trimpath -o ./bin/cluster ./cmd/cluster
	# go build -ldflags="-w -s -X main.major=1 -X main.minor=1 -X main.version=${verNum} -X main.buildTime=${buildTime} -linkmode external -extldflags -static" -buildmode=pie -trimpath ./cmd/cluster

grpc:
	mkdir -p ./bin
	cd cmd/e4ting/ && env CGO_ENABLED=0 go build -o ../../bin/server_grpc ./e4ting.go
	cd cmd/e4ting/ && env CGO_ENABLED=0 go build -o ../../bin/test_grpc  ./test/test.go

arm:
	env GOARCH=arm64 CGO_ENABLED=0 go build  -ldflags "-w -extldflags -static" -o ./bin/wick.arm64 ./cmd/wick
	env GOARCH=arm64 CGO_ENABLED=0 go build -ldflags="-w -s -X main.major=1 -X main.minor=1 -X main.version=${verNum} -X main.buildTime=${buildTime} -extldflags -static" -buildmode=pie -trimpath -o ./bin/cluster.arm64 ./cmd/cluster

deps:
	# go get github.com/s-things/wick/cmd/wick
	go mod tidy

test:
	go test github.com/s-things/wick/cmd/wick -v
	go test github.com/s-things/wick/core -v

clean:
	rm -f wick cluster
